//
//  LBSearchBar.m
//  LBWeibo
//
//  Created by 卢玉强 on 16/3/9.
//  Copyright © 2016年 Label. All rights reserved.
//

#import "LBSearchBar.h"

@implementation LBSearchBar

+ (instancetype)searchBar {
        return [[self alloc] init];
}

- (instancetype)initWithFrame:(CGRect)frame
{
        if (self=[super initWithFrame:frame]) {
                // 1. 创建UIImageView；
                // UIImageView创建方式1-使用图片，其尺寸被默认设置为图片尺寸；
                // UIImageView *searchIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
                // UIImageView创建方式2-init，其尺寸被默认设置为0，需要手动设置；
                UIImageView *searchIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
                [searchIcon setImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
                [searchIcon setContentMode:UIViewContentModeCenter];
                
                // 2. 设置UITextField属性；
                [self setBackground:[UIImage imageNamed:@"searchbar_textfield_background"]];
                [self setFont:[UIFont systemFontOfSize:14]];
                [self setLeftView:searchIcon];
                [self setLeftViewMode:UITextFieldViewModeAlways];
                [self setPlaceholder:@"搜索"];
        }
        return self;
}

@end
